package main

import "fmt"

/**
结构体
 */
func main() {
	// 创建一个新的结构体
	fmt.Println(Books{"Go语言", "杨明华", "Go语言教程", 9527})

	// 也可以使用 key == value 模式
	fmt.Println(Books{title: "Go语言", author: "杨明星", subject: "Golang教程", book_id: 9528})

	// 忽略的字段 0或空
	fmt.Println(Books{title: "Go语言", author: "杨明华"})

	var Book1 Books //声明Book1为Books类型
	var Book2 Books //声明Book2为Books类型

	/** Book1 **/
	Book1.title = "Python语言"
	Book1.title = "Golang语言"
	Book1.author = "杨明华"
	Book1.subject = "GoLang"
	Book1.book_id = 1001

	/** Book2 **/
	Book2.title = "Python语言"
	Book2.title = "Golang语言"
	Book2.author = "杨明华"
	Book2.subject = "GoLang"
	Book2.book_id = 1001

	/** 打印Book1 信息 **/
	fmt.Println("Book 1 title:  ", Book1.title)
	fmt.Println("Book 1 author:  ", Book1.author)
	fmt.Println("Book 1 subject:  ", Book1.subject)
	fmt.Println("Book 1 book_id:  ", Book1.book_id)

	/** 打印Book2 信息 **/
	fmt.Println("Book 2 title:  %s\n", Book2.title)
	fmt.Println("Book 2 author:  %s\n", Book2.author)
	fmt.Println("Book 2 subject:  %s\n", Book2.subject)
	fmt.Println("Book 2 book_id:  %s\n", Book2.book_id)

}

type Books struct {
	title   string
	author  string
	subject string
	book_id int
}
